package com.zhilianbao.leyaogo.view.dialog;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.bql.convenientlog.CLog;
import com.zhilianbao.leyaogo.R;
import com.zhilianbao.leyaogo.constants.IntentConfig;
import com.zhilianbao.leyaogo.model.response.Coupon.CanUseCoupon;
import com.zhilianbao.leyaogo.ui.adapter.shoppingcart.CouponCanUseAdapter;

import java.util.List;

/**
 * Author: hcy
 * Description:
 * Created: 2016/11/29 17:42
 */
public class CouponDialog extends BaseCouponDialog implements CouponCanUseAdapter.OnCheckChangeListener {

   private List<CanUseCoupon> mList;
    private int pos = -1;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mList = getArguments().getParcelableArrayList(IntentConfig.COUPON_DATA);
    }

    @Override
    void setData() {
        CLog.i("hcy","mList="+mList.size());
        mCenterTv.setText(getString(R.string.coupon_ticket));
        CouponCanUseAdapter adapter = new CouponCanUseAdapter(getActivity(),mList,pos);
        adapter.setOnCheckChangeListener(this);
        mRecyclerView.setAdapter(adapter);
    }

    @Override
    String getHeaderText() {
        return getString(R.string.use_one_time);
    }


    @Override
    public void checkChange(int pos) {
        this.pos = pos;
    }

    @Override
    protected void OnConfirmClick() {
        super.OnConfirmClick();
        if(mOnConfirmClickListener!=null){
            mOnConfirmClickListener.onConfirmClick(pos);
        }
        dismiss();
    }

    public void setOnConfirmClickListener(OnConfirmClickListener listener){
        mOnConfirmClickListener = listener;
    }

    public interface OnConfirmClickListener{
        void onConfirmClick(int pos);
    }

    private OnConfirmClickListener mOnConfirmClickListener;
}
